package com.origin.app.app_list

import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.origin.app.R
import com.origin.app.app_list.adapter.AppAdapter
import com.origin.app.app_list.bean.AppInfo
import com.origin.app.business.net.NetViewModel
import com.origin.app.databinding.ActivityAppListBinding
import com.origin.baselibrary.activity.style.ImmersiveActivity
import com.origin.baselibrary.activity.style.ViewModelActivity
import com.origin.uilibrary.xrecycleview.adapter.BaseRecycleAdapter

class AppListActivity :
    ViewModelActivity<ActivityAppListBinding, AppListViewModel>(R.layout.activity_app_list) {

    private val appAdapter: AppAdapter by lazy {
        AppAdapter(viewModel.appInfoList, mContext);
    }


    override fun pageLogical() {
        viewModel.appInfoList.mutableListState.observe(this, {
            appAdapter.notifyDataSetChanged()
        })
        viewModel.getAppList()
        contentViewBinding.appAdapter = appAdapter
        appAdapter.mItemClickListener = object : BaseRecycleAdapter.OnItemClickListener<AppInfo> {
            override fun onItemClick(position: Int,item:AppInfo,view: View?) {
                val appInfo = viewModel.appInfoList[position]
                val intent = Intent();
                intent.action = "android.intent.action.VIEW";//Intent.ACTION_VIEW
                val contentUrl = Uri.parse(appInfo.url);
                intent.data = contentUrl;
                startActivity(intent);
            }

        }
    }

    override fun initContentView() {

    }

}